#qpy:pygame


import sys
f = open('log.py', 'w')
sys.stdout = f
sys.stderr = f


import pygame as pg

from math import pi, cos, sin
tau = pi * 2



class V2(object):
  def __init__(self, x, y=None):
    if y is None:
      x, y = x
    self.x = float(x)
    self.y = float(y)
  
  def __repr__(self):
    return repr([self.x, self.y])
  
  def __add__(a, b):
    return V2(a.x + b.x, a.y + b.y)
  
  def __sub__(a, b):
    return V2(a.x - b.x, a.y - b.y)
    
  def __mul__(self, k):
    return V2(self.x * k, self.y * k)

  def __rmul__(self, k):
    return V2(self.x * k, self.y * k)

  def __div__(self, k):
    return V2(self.x / k, self.y / k)
  
  def __getitem__(self, n):
    return (self.x, self.y)[n]
  
  def t(self):
    return (self.x, self.y)
  
  def dot(a, b):
    return a.x * b.x + a.y * b.y
    
  def length(self):
    return (self.x ** 2 + self.y ** 2) ** 0.5
  
  def norm(self):
    return self / self.length()
  
  
    

def o(p):
  x, y = p
  return (t1  + x * 200, t2 - y * 200)

def rel(p, p0, rot):
  #return p
  x, y = p
  s, c = sin(rot), cos(rot)
  return V2(x * c + y * s, -x * s + y * c) + p0

v = [(1, 0.2), (-1, 0.2), (-1, -0.2), (1, -0.2)]

v = [(1, 1), (-1, 1), (-1, -1), (1, -1)]



def render():
  screen.fill((0, 0, 0))
  
 
  p = V2(cos(t), sin(t))
  th = -t + pi / 2
  pg.draw.polygon(screen, (255, 255, 255, 128), [o(rel(q, p, th)) for q in v])
 
  
  p = V2(cos(t*2), sin(t*2))
  th = -t*2 + pi / 2
  pg.draw.polygon(screen, (255, 255, 255, 128), [o(rel(q, p, th)) for q in v])
 
  
  p = V2(cos(t*3), sin(t*3))
  th = -t*3 + pi / 2
  pg.draw.polygon(screen, (255, 255, 255, 128), [o(rel(q, p, th)) for q in v])


pg.init()
print(repr(pg.version.vernum))
screen = pg.display.set_mode((10,10))
t = 0
size = screen.get_size()
t1, t2 = size[0] / 2, size[1] / 2

pg.SRCALPHA
clock = pg.time.Clock()
while True:
  dt = clock.tick(40) / 1000.0
  t += dt
  for e in pg.event.get():
    pass
  
  render()
      
  pg.display.update()
        	
      

